package com.yaozheng.vocationaltraining.service.impl.checkpoints_trip;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBaseView;
import com.yaozheng.vocationaltraining.iview.checkpoints_trip.ICheckpointsTripView;
import com.yaozheng.vocationaltraining.service.checkpoints_trip.CheckpointsTripService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * 闯关
 */
@EBean
public class CheckpointsTripServiceImpl implements CheckpointsTripService {
    ICheckpointsTripView iCheckpointsTripView;

    @Override
    public void init(ICheckpointsTripView iCheckpointsTripView) {
        this.iCheckpointsTripView = iCheckpointsTripView;
    }

    @Background
    @Override
    public void getCheckpointsTripInfo() {
        try {
            OkHttpClientManager.getInstance().get(
                    Constants.ROOTURL + "/exam/advanced/info",
                    iCheckpointsTripView.getToken(), new BaseView(iCheckpointsTripView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iCheckpointsTripView.checkpointsTripInfoSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iCheckpointsTripView.checkpointsTripInfoError(error);
                        }

                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iCheckpointsTripView.isResponseResult()) {
                iCheckpointsTripView
                        .checkpointsTripInfoError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }
}
